<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <link rel="stylesheet" href="bulma.min.css">
  <style>
    [v-cloak]{
      display: none;
    }
    .box {
      width: 1200px;
      margin: 0 auto;
    }

    .num {
      width: 100px;
    }
    .intro{
      width: 500px;
    }
    input{
      text-align: center;
    }
  </style>
</head>
<body>
  <!-- 
    --------------------------------1. 循环渲染数据    
    --------------------------------2. 商品加个保留2位小数
    --------------------------------3. 按钮改变数量++ -- （选做）
    --------------------------------4. 商品小计改变价格（选做）
    --------------------------------5. 删除（选做）

    了解：什么是MVVM，什么是双向数据绑定，渐进式和声明式
  -->
  <div id="app" v-cloak>
    <div class="box">
      <table class="table">
        <thead>
          <tr>
            <th></th>
            <th>商品图片</th>
            <th>商品介绍</th>
            <th>商品价格</th>
            <th>商品数量</th>
            <th>商品小计</th>
            <th>操作</th>
          </tr>
        </thead>
        <tbody>
          <tr v-for="(item , index) in arr">
            <td><input type="checkbox" v-bind:checked="arr[index].flag"></td>
            <td><img width="80" height="80" v-bind:src="arr[index].imgUrl" />
            </td>
            <td>
              <p class="intro">{{arr[index].txt}}</p>
            </td>
            <td>￥{{(Number(arr[index].price)).toFixed(2)}}</td>
            <td>
              <div>
                <button @click="arr[index].num --" class="button is-small">-</button>
                <input type="text" v-bind:value="(String(arr[index].num).match(/^[0-9]*[1-9][0-9]*$/))? arr[index].num : arr[index].num = 0" class="input num is-small">
                <button @click="arr[index].num ++" class="button is-small">+</button>
              </div>
            </td>
            <td>
              <b>{{(arr[index].price * arr[index].num).toFixed(2)}}</b>
            </td>
            <td><span @click="arr.splice(index , 1)">删除</span></td>
          </tr>
          
        </tbody>
      </table>
    </div>
  </div>
  <script src="Vue.js"></script>
  <script>
    Vue.createApp({
      data() {
        return {
          arr: [
            {
              flag: true,
              imgUrl: 'https://img12.360buyimg.com/n7/jfs/t1/182913/10/30630/75042/64703b85Fbd5c279c/60dfec127dd8ba37.jpg',
              txt: 'SHIMANO禧玛诺 阿德CQ BFS库拉多水滴鼓轮微物马口白条溪流路亚轮 23款CQ',
              price: '3499',
              num: 2
            },
            {
              flag: false,
              imgUrl: 'https://img12.360buyimg.com/n7/jfs/t1/182913/10/30630/75042/64703b85Fbd5c279c/60dfec127dd8ba37.jpg',
              txt: '加特林 无限 .56',
              price: '2399',
              num: 1
            },
            {
              flag: true,
              imgUrl: 'https://img12.360buyimg.com/n7/jfs/t1/182913/10/30630/75042/64703b85Fbd5c279c/60dfec127dd8ba37.jpg',
              txt: '手榴弹 水弹 10公分',
              price: '3',
              num: 1
            }
          ]
        }
      }
    }).mount('#app')
  </script>
</body>
</html>